using Boo.Lang;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;

[Serializable]
public class spin : MonoBehaviour
{
	[Serializable]
	[CompilerGenerated]
	internal sealed class _0024f_0024469 : GenericGenerator<WaitForSeconds>
	{
		internal spin _0024self__0024471;

		public _0024f_0024469(spin self_)
		{
			_0024self__0024471 = self_;
		}

		public override IEnumerator<WaitForSeconds> GetEnumerator()
		{
			return new _0024(_0024self__0024471);
		}
	}

	[Serializable]
	[CompilerGenerated]
	internal sealed class _0024getaccel_0024472 : GenericGenerator<WaitForSeconds>
	{
		internal spin _0024self__0024474;

		public _0024getaccel_0024472(spin self_)
		{
			_0024self__0024474 = self_;
		}

		public override IEnumerator<WaitForSeconds> GetEnumerator()
		{
			return new _0024(_0024self__0024474);
		}
	}

	private Rigidbody body;

	public GameObject extraspeed;

	[HideInInspector]
	public int spinvelocity;

	public int rotationSpeed;

	[HideInInspector]
	public bool controllable;

	public bool AI;

	[HideInInspector]
	public int speed;

	[HideInInspector]
	public int RPM;

	public GUIText RPMtext;

	private int st;

	public winlosedraw wld;

	private float calibratey;

	private float calibratex;

	public bool touchcontrol;

	[HideInInspector]
	public float touchz;

	[HideInInspector]
	public float touchx;

	public bool mp;

	private float sensitivity;

	public spin()
	{
		spinvelocity = 500;
		rotationSpeed = 10;
		sensitivity = 1f;
	}

	public void Start()
	{
		body = GetComponent<Rigidbody>();
		if (AI)
		{
			float[] array = new float[12]
			{
				580f,
				560f,
				555f,
				535f,
				460f,
				450f,
				435f,
				420f,
				395f,
				285f,
				260f,
				100f
			};
			spinvelocity = (int)(array[UnityEngine.Random.Range(0, array.Length)] + (float)UnityEngine.Random.Range(10, 100));
		}
		if (PlayerPrefs.GetInt("RCord") == 0)
		{
			body.maxAngularVelocity = 314f;
		}
		else if (PlayerPrefs.GetInt("RCord") == 1)
		{
			body.maxAngularVelocity = 319f;
		}
		else if (PlayerPrefs.GetInt("RCord") == 2)
		{
			body.maxAngularVelocity = 324f;
		}
		else if (PlayerPrefs.GetInt("RCord") == 3)
		{
			body.maxAngularVelocity = 330f;
		}
		else
		{
			body.maxAngularVelocity = 314f;
		}
		StartCoroutine(getaccel());
		sensitivity = PlayerPrefs.GetFloat("Sensitivity");
		InvokeRepeating("check", 0f, 0.15f);
		if (PlayerPrefs.GetInt("TouchControl") >= 1)
		{
			touchcontrol = true;
			InvokeRepeating("touch", 5f, 0.1f);
		}
		else
		{
			InvokeRepeating("accel", 5f, 0.1f);
		}
		if (mp && !RPMtext)
		{
			RPMtext = (((GUIText)GameObject.Find("GUI Text1").GetComponent(typeof(GUIText))) as GUIText);
		}
	}

	public void ifai()
	{
		if (AI)
		{
			CancelInvoke("kbrd");
			CancelInvoke("accel");
			CancelInvoke("touch");
		}
	}

	public void check()
	{
		speed = (int)(body.angularVelocity.sqrMagnitude / 15f);
		RPMtext.text = speed.ToString();
	}

	public void accel()
	{
		Vector3 acceleration = Input.acceleration;
		float x = acceleration.x * 1.4f * sensitivity - calibratex;
		float y = 0f;
		Vector3 acceleration2 = Input.acceleration;
		Vector3 a = new Vector3(x, y, acceleration2.y * 1.4f * sensitivity + calibratey);
		body.AddForce(a * 138f * (body.mass / 1.75f));
	}

	public void touch()
	{
		Vector3 a = new Vector3(touchx, 0f, touchz);
		body.AddForce(a * 100f * sensitivity * (body.mass / 1.75f));
	}

	public void kbrd()
	{
		Vector3 a = new Vector3(UnityEngine.Input.GetAxis("Horizontal") * sensitivity, 0f, UnityEngine.Input.GetAxis("Vertical") * sensitivity);
		body.AddForce(a * 90f * (body.mass / 1.75f));
	}

	public void spin()
	{
		AudioSource.PlayClipAtPoint(Resources.Load("TopLaunch") as AudioClip, Camera.main.transform.position);
		body.isKinematic = false;
		body.AddRelativeTorque(0f, spinvelocity, 0f);
		StartCoroutine(f());
		GetComponent<Rigidbody>().isKinematic = false;
	}

	public IEnumerator f()
	{
		return new _0024f_0024469(this).GetEnumerator();
	}

	public IEnumerator getaccel()
	{
		return new _0024getaccel_0024472(this).GetEnumerator();
	}

	public void Main()
	{
		CancelInvoke();
		Invoke("ifai", 1f);
	}
}
